package com.example.juc.kingdom_adventures.term7;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Client1 {
    private final ReentrantLock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();

    private boolean writeComplete = false;

    private void read() {
        lock.lock();

        // 这就像线程睡觉前，先给自己定了一个闹钟，如果没人唤醒自己，就自己醒过来
        try {
            if (condition.await(1, TimeUnit.SECONDS)) {
                // 1 秒内被 signal 唤醒
            } else {
                // 1 秒内没有被唤醒，自己醒来
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        lock.unlock();
    }

}
